package com.songVersion.services.impl;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.songVersion.model.NestCache;
import com.songVersion.services.NestCacheManager;
import com.songVersion.utils.PMF;

public class NestCacheManagerImpl extends ManagerImpl<NestCache> implements
		NestCacheManager
{

	@SuppressWarnings("unchecked")
	@Override
	public NestCache load(String title, String author, int pageNumber)
	{
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try
		{
			Query query = pm.newQuery(NestCache.class);
			query.setFilter("author == authorParam && title == tittleParam && pageNumber == pageNumberParam");
			query.declareParameters("String authorParam, String tittleParam,, int pageNumberParam");
			System.out.println("author => " + author);
			System.out.println("title => " + title);
			System.out.println("pageNumber => " + pageNumber);
			
			List<NestCache> l = (List<NestCache>) query.execute(author, title, pageNumber);
			NestCache res = null;
			System.out.println(l);
			if (l != null && l.size() > 0)
			{
//				System.out.println(l.get(0).getSongs().get(0).getYoutubeInfo().getThumbnails().size());
				res = new NestCache(l.get(0));
//				System.out.println("!!!!" + res.getSongs().get(0)
//						.getYoutubeInfo().getThumbnails());
			}
			return res;
		} finally
		{
			pm.close();
		}
	}

	@Override
	public void init()
	{
		this.t = new NestCache("", "", 1);
		
	}

}
